package ch.headshot.photomap.client.gpx.impl;

import ch.headshot.photomap.client.gpx.Link;

import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;

public class LinkImpl implements Link {

	private static final String HREF = "href";
	private static final String NAME = "name";
	private static final String TYPE = "type";
	private final Element item;

	public LinkImpl(Element item) {
		this.item = item;
	}

	public String getHref() {
		return item.getAttribute(HREF);
	}

	public String getText() {
		NodeList elems = item.getElementsByTagName(NAME);
		return elems.getLength() > 0 ? ((Element) elems.item(0)).getNodeValue() : null;
	}

	public String getType() {
		NodeList elems = item.getElementsByTagName(TYPE);
		return elems.getLength() > 0 ? ((Element) elems.item(0)).getNodeValue() : null;
	}

}
